﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Web
{
    public partial class index : WebCommon
    {
        public string uname;

        public List<Model.tb_menu> mlist = new List<Model.tb_menu>();
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            int uid=Convert.ToInt32(Common.UICookie.ReadCookie("UId"));
            var model = Common.SqlExption.GetList<Model.tb_user>().FirstOrDefault(c => c.Id.Equals(uid));
            uname = model.name;

            var this_mlist = Common.SqlExption.GetList<Model.tb_menu>();
            if (this_mlist.Count()>0)
            {
                var gxlist = Common.SqlExption.GetList<Model.tb_role_user>().Where(c => c.rid.Equals(model.roleid));
                if (gxlist.Count() > 0)
                {
                    foreach (var mitem in this_mlist)
                    {
                        foreach (var item in gxlist)
                        {
                            Model.tb_menu m = new Model.tb_menu()
                            {
                                Id = mitem.Id,
                                Name = mitem.Name,
                                Pid = mitem.Pid,
                                Urls = mitem.Urls
                            };
                            if (mitem.Id.Equals(item.mid))
                            {
                                mlist.Add(m);
                            }
                        }
                      
                    }
                }
            }
            
        }
    }
}